import axios from 'axios'


const url = 'https://www.netss.cn/up'
const dirName = 'test'

export default{

	
	// 上传文件
	uploadFile(upload_path, file, token='', bucket='', type='img', editor=''){
		if(!token || !upload_path){
			alert('参数错误')
			return false
		}

		let url = upload_path

		let params = new FormData();
		// let timeer = Date.now();
		params.append("file", file);
		params.append("bucket", bucket);
		axios.defaults.headers.common['token'] = token
		axios.defaults.timeout = 800000

		if(editor){ // 判断是否是wangeditor编辑器
			params.append("type", editor);
		}else{
			params.append("type", type);
		}
		return axios.post(url, params)
	},

    // 验证图片类型
    fileTypeCheck(file, type="img"){
        if (type == 'img') {
            if(file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image/gif'){
                return false
            }
            return true
        }
    }

}
